import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_SDR } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询调度日志列表数据
 * @async
 * @function fetchLogsList
 * @param {Object} params - 查询参数
 */

export function fetchLogsList(_x) {
  return _fetchLogsList.apply(this, arguments);
}
/**
 * 删除
 * @async
 * @function deleteLogs
 * @param {object} params - 参数
 */

function _fetchLogsList() {
  _fetchLogsList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs") : "".concat(CPAAS_SDR, "/v1/job-logs"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchLogsList.apply(this, arguments);
}

export function deleteLogs(_x2) {
  return _deleteLogs.apply(this, arguments);
}
/**
 * 清除日志
 * @async
 * @function clearLogs
 * @param {object} params - 参数
 */

function _deleteLogs() {
  _deleteLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs") : "".concat(CPAAS_SDR, "/v1/job-logs"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _deleteLogs.apply(this, arguments);
}

export function clearLogs(_x3) {
  return _clearLogs.apply(this, arguments);
}
/**
 * 查询错误日志详情
 * @async
 * @function fetchErrorDetail
 * @param {Object} params - 查询参数
 */

function _clearLogs() {
  _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var api;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            api = organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs/clear") : "".concat(CPAAS_SDR, "/v1/job-logs/clear");
            return _context3.abrupt("return", request(api, {
              method: 'DELETE',
              query: params
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _clearLogs.apply(this, arguments);
}

export function fetchErrorDetail(_x4) {
  return _fetchErrorDetail.apply(this, arguments);
}
/**
 * 查询日志详情
 * @async
 * @function fetchLogDetail
 * @param {Object} params - 查询参数
 */

function _fetchErrorDetail() {
  _fetchErrorDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs/").concat(params.logId, "/error-detail") : "".concat(CPAAS_SDR, "/v1/job-logs/").concat(params.logId, "/error-detail"), {
              method: 'GET',
              responseType: 'text'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _fetchErrorDetail.apply(this, arguments);
}

export function fetchLogDetail(_x5) {
  return _fetchLogDetail.apply(this, arguments);
}
/**
 * 获取任务进度
 * @async
 * @function fetchProgress
 * @param {Object} params - 查询参数
 */

function _fetchLogDetail() {
  _fetchLogDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs/").concat(params.logId, "/log-detail") : "".concat(CPAAS_SDR, "/v1/job-logs/").concat(params.logId, "/log-detail"), {
              method: 'GET',
              responseType: 'text'
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _fetchLogDetail.apply(this, arguments);
}

export function fetchProgress(_x6) {
  return _fetchProgress.apply(this, arguments);
}

function _fetchProgress() {
  _fetchProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs/").concat(params.logId, "/progress") : "".concat(CPAAS_SDR, "/v1/job-logs/").concat(params.logId, "/progress"), {
              method: 'GET',
              responseType: 'text'
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchProgress.apply(this, arguments);
}